//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.ty.basic.response;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.parser.Feature;
import com.alibaba.fastjson.serializer.SerializeConfig;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.serializer.SimpleDateFormatSerializer;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.hustcad.plm.basic.log.TyplmLogger;
import com.hustcad.plm.basic.service.TyplmNotify;
import com.hustcad.plm.basic.service.TyplmObjectAliasService;
import com.ty.basic.exception.MessageException;
import com.ty.basic.exception.message.ErrorCodeEnum;
import com.ty.basic.exception.message.MessageBoxIconEnum;
import com.ty.basic.session.TyAccountContext;
import com.ty.basic.util.JsonSerializeConfig;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.persistence.Transient;

import lombok.AllArgsConstructor;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;
@Primary
@Component
public class ResponseResult<T> implements Serializable {
    private static final long serialVersionUID = -7701302570649482185L;
    private String result;
    private String traceId;
    private ResponseErrorsInfo errors;
    private boolean success;
    private String code;
    private String message;
    private List<String> messages;
    private MessageBoxIconEnum messageBoxIcon;
    private transient T data;
    public static final String RESULT_SUCCESS = "SUCCESS";
    public static final String ERROR = "ERROR";
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date time;
    @JsonIgnore
    @Transient
    private static ResponseResult tyResponseResult;
    @JsonIgnore
    @Resource
    private transient TyplmLogger logger;
    @JsonIgnore
    @Resource
    private transient TyplmNotify notify;
    @JsonIgnore
    @Resource
    private transient TyplmObjectAliasService typlmObjectAliasService;

    @PostConstruct
    public void initLogger() {
        initBean(this);
    }

    private static void initBean(ResponseResult responseResult) {
        tyResponseResult = responseResult;
        tyResponseResult.logger = responseResult.logger;
        tyResponseResult.notify = responseResult.notify;
    }

    public ResponseResult() {
        this.time = new Date();
    }

    public static <T> ResponseResult<T> result(String result) {
        ResponseResult<T> response = new ResponseResult();
        response.setResult(result);
        response.setSuccess("SUCCESS".equals(result));
        response.setMessageBoxIcon(MessageBoxIconEnum.INFO);
        return response;
    }

    public static <T> ResponseResult<T> result(boolean result) {
        ResponseResult<T> response = new ResponseResult();
        if (result) {
            response.setResult("SUCCESS");
        } else {
            response.setResult("ERROR");
        }

        response.setMessageBoxIcon(MessageBoxIconEnum.INFO);
        response.setSuccess(result);
        return response;
    }

    public static <T> ResponseResult<T> success() {
        ResponseResult<T> response = result("SUCCESS");
        response.setMessageBoxIcon(MessageBoxIconEnum.INFO);
        tyResponseResult.logger.sendCollectInfo();
        tyResponseResult.notify.sendCollectInfo();
        if (!ObjectUtils.isEmpty(TyAccountContext.getBizLogHolder())) {
            TyAccountContext.cleanBizLogHolder();
        }

        return response;
    }

    public static <T> ResponseResult success(T data) {
        if (!(data instanceof JSON) && (!(data instanceof List) || ((List)data).isEmpty() || !(((List)data).get(0) instanceof JSON))) {
            return getSuccess(data);
        } else {
            SerializeConfig serializeConfig = JsonSerializeConfig.SERIALIZE_CONFIG;
            serializeConfig.put(Date.class, new SimpleDateFormatSerializer("yyyy-MM-dd HH:mm:ss"));
            String jsonStr = JSON.toJSONString(data, serializeConfig, new SerializerFeature[]{SerializerFeature.WriteNullStringAsEmpty, SerializerFeature.WriteMapNullValue});
            Object obj = JSON.parse(jsonStr, new Feature[]{Feature.OrderedField});
            return getSuccess(obj);
        }
    }

    public static <T> ResponseResult success(T data, boolean outputNull) {
        if (!(data instanceof JSON) && (!(data instanceof List) || ((List)data).isEmpty() || !(((List)data).get(0) instanceof JSON)) && !outputNull) {
            return getSuccess(data);
        } else {
            SerializeConfig serializeConfig = JsonSerializeConfig.SERIALIZE_CONFIG;
            serializeConfig.put(Date.class, new SimpleDateFormatSerializer("yyyy-MM-dd HH:mm:ss"));
            String jsonStr = JSON.toJSONString(data, serializeConfig, new SerializerFeature[]{SerializerFeature.WriteNullStringAsEmpty, SerializerFeature.WriteMapNullValue, SerializerFeature.WriteNullListAsEmpty});
            Object obj = JSON.parse(jsonStr, new Feature[]{Feature.OrderedField});
            return getSuccess(obj);
        }
    }

    private static <T> ResponseResult<T> getSuccess(T data) {
        ResponseResult<T> response = result("SUCCESS");
        response.setMessageBoxIcon(MessageBoxIconEnum.INFO);
        response.setData(data);
        tyResponseResult.logger.sendCollectInfo();
        tyResponseResult.notify.sendCollectInfo();
        if (!ObjectUtils.isEmpty(TyAccountContext.getBizLogHolder())) {
            TyAccountContext.cleanBizLogHolder();
        }

        return response;
    }

    public static <T> ResponseResult<T> fail(String code, String msg) {
        return fail(code, msg, MessageBoxIconEnum.INFO);
    }

    public static <T> ResponseResult<T> fail(String code, String msg, MessageBoxIconEnum messageBoxIcon) {
        ResponseResult<T> response = result("ERROR");
        response.setMessageBoxIcon(messageBoxIcon);
        response.setCode(code);
        response.setMessage(msg);
        ResponseErrorsInfo responseErrorsInfo = new ResponseErrorsInfo();
        responseErrorsInfo.setCode(code);
        responseErrorsInfo.setMessage(msg);
        responseErrorsInfo.setDetail(msg);
        response.setErrors(responseErrorsInfo);
        return response;
    }

    public static <T> ResponseResult<T> fail(String code, List<String> msgs, MessageBoxIconEnum messageBoxIcon) {
        ResponseResult<T> response = result("ERROR");
        response.setMessageBoxIcon(messageBoxIcon);
        response.setCode(code);
        response.setMessages(msgs);
        String msg = String.join(";", msgs);
        response.setMessage(msg);
        ResponseErrorsInfo responseErrorsInfo = new ResponseErrorsInfo();
        responseErrorsInfo.setCode(code);
        responseErrorsInfo.setMessage(msg);
        responseErrorsInfo.setDetail(msg);
        response.setErrors(responseErrorsInfo);
        return response;
    }

    public static <T> ResponseResult<T> fail(ErrorCodeEnum errorCodeEnum) {
        return fail(errorCodeEnum, MessageBoxIconEnum.INFO);
    }

    public static <T> ResponseResult<T> fail(ErrorCodeEnum errorCodeEnum, MessageBoxIconEnum messageBoxIcon) {
        ResponseResult<T> response = result("ERROR");
        response.setMessageBoxIcon(messageBoxIcon);
        response.setCode(errorCodeEnum.getCode());
        response.setMessage(errorCodeEnum.getMsg());
        ResponseErrorsInfo responseErrorsInfo = new ResponseErrorsInfo();
        responseErrorsInfo.setCode(errorCodeEnum.getCode());
        responseErrorsInfo.setMessage(errorCodeEnum.getMsg());
        responseErrorsInfo.setDetail(responseErrorsInfo.getMessage());
        response.setErrors(responseErrorsInfo);
        return response;
    }

    public static <T> ResponseResult<T> fail(MessageException messageException) {
        return fail(messageException, MessageBoxIconEnum.INFO);
    }

    public static <T> ResponseResult<T> fail(MessageException messageException, MessageBoxIconEnum messageBoxIcon) {
        ResponseResult<T> response = result("ERROR");
        response.setMessageBoxIcon(messageBoxIcon);
        response.setCode(messageException.getErrorCode());
        response.setMessage(messageException.getMessage());
        ResponseErrorsInfo responseErrorsInfo = new ResponseErrorsInfo();
        responseErrorsInfo.setCode(messageException.getErrorCode());
        responseErrorsInfo.setMessage(messageException.getMessage());
        responseErrorsInfo.setDetail(responseErrorsInfo.getMessage());
        response.setErrors(responseErrorsInfo);
        return response;
    }

    public ResponseResult(final String result, final String traceId, final ResponseErrorsInfo errors, final boolean success, final String code, final String message, final List<String> messages, final MessageBoxIconEnum messageBoxIcon, final T data, final Date time, final TyplmLogger logger, final TyplmNotify notify, final TyplmObjectAliasService typlmObjectAliasService) {
        this.result = result;
        this.traceId = traceId;
        this.errors = errors;
        this.success = success;
        this.code = code;
        this.message = message;
        this.messages = messages;
        this.messageBoxIcon = messageBoxIcon;
        this.data = data;
        this.time = time;
        this.logger = logger;
        this.notify = notify;
        this.typlmObjectAliasService = typlmObjectAliasService;
    }

    public String getResult() {
        return this.result;
    }

    public String getTraceId() {
        return this.traceId;
    }

    public ResponseErrorsInfo getErrors() {
        return this.errors;
    }

    public boolean isSuccess() {
        return this.success;
    }

    public String getCode() {
        return this.code;
    }

    public String getMessage() {
        return this.message;
    }

    public List<String> getMessages() {
        return this.messages;
    }

    public MessageBoxIconEnum getMessageBoxIcon() {
        return this.messageBoxIcon;
    }

    public T getData() {
        return this.data;
    }

    public Date getTime() {
        return this.time;
    }

    public TyplmLogger getLogger() {
        return this.logger;
    }

    public TyplmNotify getNotify() {
        return this.notify;
    }

    public TyplmObjectAliasService getTyplmObjectAliasService() {
        return this.typlmObjectAliasService;
    }

    public ResponseResult<T> setResult(final String result) {
        this.result = result;
        return this;
    }

    public ResponseResult<T> setTraceId(final String traceId) {
        this.traceId = traceId;
        return this;
    }

    public ResponseResult<T> setErrors(final ResponseErrorsInfo errors) {
        this.errors = errors;
        return this;
    }

    public ResponseResult<T> setSuccess(final boolean success) {
        this.success = success;
        return this;
    }

    public ResponseResult<T> setCode(final String code) {
        this.code = code;
        return this;
    }

    public ResponseResult<T> setMessage(final String message) {
        this.message = message;
        return this;
    }

    public ResponseResult<T> setMessages(final List<String> messages) {
        this.messages = messages;
        return this;
    }

    public ResponseResult<T> setMessageBoxIcon(final MessageBoxIconEnum messageBoxIcon) {
        this.messageBoxIcon = messageBoxIcon;
        return this;
    }

    public ResponseResult<T> setData(final T data) {
        this.data = data;
        return this;
    }

    public ResponseResult<T> setTime(final Date time) {
        this.time = time;
        return this;
    }

    @JsonIgnore
    public ResponseResult<T> setLogger(final TyplmLogger logger) {
        this.logger = logger;
        return this;
    }

    @JsonIgnore
    public ResponseResult<T> setNotify(final TyplmNotify notify) {
        this.notify = notify;
        return this;
    }

    @JsonIgnore
    public ResponseResult<T> setTyplmObjectAliasService(final TyplmObjectAliasService typlmObjectAliasService) {
        this.typlmObjectAliasService = typlmObjectAliasService;
        return this;
    }

    public boolean equals(final Object o) {
        if (o == this) {
            return true;
        } else if (!(o instanceof ResponseResult)) {
            return false;
        } else {
            ResponseResult<?> other = (ResponseResult)o;
            if (!other.canEqual(this)) {
                return false;
            } else if (this.isSuccess() != other.isSuccess()) {
                return false;
            } else {
                label109: {
                    Object this$result = this.getResult();
                    Object other$result = other.getResult();
                    if (this$result == null) {
                        if (other$result == null) {
                            break label109;
                        }
                    } else if (this$result.equals(other$result)) {
                        break label109;
                    }

                    return false;
                }

                label102: {
                    Object this$traceId = this.getTraceId();
                    Object other$traceId = other.getTraceId();
                    if (this$traceId == null) {
                        if (other$traceId == null) {
                            break label102;
                        }
                    } else if (this$traceId.equals(other$traceId)) {
                        break label102;
                    }

                    return false;
                }

                Object this$errors = this.getErrors();
                Object other$errors = other.getErrors();
                if (this$errors == null) {
                    if (other$errors != null) {
                        return false;
                    }
                } else if (!this$errors.equals(other$errors)) {
                    return false;
                }

                label88: {
                    Object this$code = this.getCode();
                    Object other$code = other.getCode();
                    if (this$code == null) {
                        if (other$code == null) {
                            break label88;
                        }
                    } else if (this$code.equals(other$code)) {
                        break label88;
                    }

                    return false;
                }

                Object this$message = this.getMessage();
                Object other$message = other.getMessage();
                if (this$message == null) {
                    if (other$message != null) {
                        return false;
                    }
                } else if (!this$message.equals(other$message)) {
                    return false;
                }

                label74: {
                    Object this$messages = this.getMessages();
                    Object other$messages = other.getMessages();
                    if (this$messages == null) {
                        if (other$messages == null) {
                            break label74;
                        }
                    } else if (this$messages.equals(other$messages)) {
                        break label74;
                    }

                    return false;
                }

                Object this$messageBoxIcon = this.getMessageBoxIcon();
                Object other$messageBoxIcon = other.getMessageBoxIcon();
                if (this$messageBoxIcon == null) {
                    if (other$messageBoxIcon != null) {
                        return false;
                    }
                } else if (!this$messageBoxIcon.equals(other$messageBoxIcon)) {
                    return false;
                }

                Object this$time = this.getTime();
                Object other$time = other.getTime();
                if (this$time == null) {
                    if (other$time != null) {
                        return false;
                    }
                } else if (!this$time.equals(other$time)) {
                    return false;
                }

                return true;
            }
        }
    }

    protected boolean canEqual(final Object other) {
        return other instanceof ResponseResult;
    }

    public int hashCode() {
        int result = 1;
        result = result * 59 + (this.isSuccess() ? 79 : 97);
        Object $result = this.getResult();
        result = result * 59 + ($result == null ? 43 : $result.hashCode());
        Object $traceId = this.getTraceId();
        result = result * 59 + ($traceId == null ? 43 : $traceId.hashCode());
        Object $errors = this.getErrors();
        result = result * 59 + ($errors == null ? 43 : $errors.hashCode());
        Object $code = this.getCode();
        result = result * 59 + ($code == null ? 43 : $code.hashCode());
        Object $message = this.getMessage();
        result = result * 59 + ($message == null ? 43 : $message.hashCode());
        Object $messages = this.getMessages();
        result = result * 59 + ($messages == null ? 43 : $messages.hashCode());
        Object $messageBoxIcon = this.getMessageBoxIcon();
        result = result * 59 + ($messageBoxIcon == null ? 43 : $messageBoxIcon.hashCode());
        Object $time = this.getTime();
        result = result * 59 + ($time == null ? 43 : $time.hashCode());
        return result;
    }

    public String toString() {
        return "ResponseResult(result=" + this.getResult() + ", traceId=" + this.getTraceId() + ", errors=" + this.getErrors() + ", success=" + this.isSuccess() + ", code=" + this.getCode() + ", message=" + this.getMessage() + ", messages=" + this.getMessages() + ", messageBoxIcon=" + this.getMessageBoxIcon() + ", data=" + this.getData() + ", time=" + this.getTime() + ", logger=" + this.getLogger() + ", notify=" + this.getNotify() + ", typlmObjectAliasService=" + this.getTyplmObjectAliasService() + ")";
    }
}
